package com.jinzhi.common.base;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.api.util.JWTUtil;
import com.jinzhi.common.service.DictService;
import com.jinzhi.common.utils.*;
import com.jinzhi.jzweb.domain.*;
import com.jinzhi.jzweb.service.*;
import com.jinzhi.jzweb.utils.IdCardUtil;
import com.jinzhi.jzweb.utils.WithZoreUtil;
import com.jinzhi.sys.domain.RoleDO;
import com.jinzhi.sys.domain.UserDO;
import com.jinzhi.sys.domain.UserRoleDO;
import com.jinzhi.sys.service.RoleService;
import com.jinzhi.sys.service.UserRoleService;
import com.jinzhi.sys.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * <pre>
 * </pre>
 *
 * <small> 2018年2月25日 | Aron</small>
 */
@Slf4j
public abstract class BaseController {

    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private UserRoleService userRoleService;
    @Autowired
    private CoursesService coursesService;
    @Autowired
    private ExaminationPaperService examinationPaperService;
    @Autowired
    private ExamineeGroupService examineeGroupService;
    @Autowired
    private DictService dictService;
    @Autowired
    private ExaminationBatchService examinationBatchService;
    @Autowired
    private ExaminationPointService examinationPointService;
    @Autowired
    private ExaminationRoomService examinationRoomService;

    private String RecoveryId="1375327865662226434";//产后恢复证书ID

    // 用户信息相关

    public UserDO getUser() {
        return ShiroUtils.getSysUser();
    }

    public Long getUserId() {
        return getUser().getId();
    }

    public static Subject getSubjct() {
        return SecurityUtils.getSubject();
    }

    public String getUsername() {
        return getUser().getUsername();
    }

    public UserDO getClientUser(String token) {
        return userService.findOneByKv("id", JWTUtil.getWxUserId(token));
    }



    // 参数请求、分页

    /**
     * <pre>
     * 自动获取分页参数，返回分页对象page
     * </pre>
     *
     * <small> 2018年4月15日 | Aron</small>
     *
     * @param e
     * @return
     */
    public <E> Page<E> getPage(Class<E> e) {
        int pageNumber = getParaToInt("pageNumber", 1);
        int pageSize = getParaToInt("pageSize", 10);
        Page<E> page = new Page<>(pageNumber, pageSize);
        //支持sort、order参数
        HttpServletRequest request = getRequest();
        String sort = request.getParameter("sort");
        if (StringUtils.isNotBlank(sort)) {
            page.setOrderByField(sort);
            String order = request.getParameter("order");
            if (StringUtils.isNotBlank(order)) {
                page.setAsc("asc".equalsIgnoreCase(order));
            }
        }
        return page;
    }


    /**
     * <pre>
     * 自动获取分页参数，返回分页对象page
     * </pre>
     *
     * <small> 2018年4月15日 | Aron</small>
     *
     * @param e
     * @return
     */
    public <E> Page<E> getPages(Class<E> e) {
        int pageNumber = getParaToInt("pageNumber", 1);
        int pageSize = getParaToInt("pageSize", 100);
        Page<E> page = new Page<>(pageNumber, pageSize);
        //支持sort、order参数
        HttpServletRequest request = getRequest();
        String sort = request.getParameter("sort");
        if (StringUtils.isNotBlank(sort)) {
            page.setOrderByField(sort);
            String order = request.getParameter("order");
            if (StringUtils.isNotBlank(order)) {
                page.setAsc("asc".equalsIgnoreCase(order));
            }
        }
        return page;
    }


    private int getParaToInt(String key, int defaultValue) {
        String pageNumber = HttpContextUtils.getHttpServletRequest().getParameter(key);
        if (StringUtils.isBlank(pageNumber)) {
            return defaultValue;
        }
        return Integer.parseInt(pageNumber);
    }

    // Servlet

    protected HttpServletRequest getRequest() {
        return HttpContextUtils.getHttpServletRequest();
    }

    protected HttpServletResponse getResponse() {
        return HttpContextUtils.getHttpServletResponse();
    }

    // 响应结果

    protected Result<String> fail() {
        return Result.fail();
    }

    protected Result<String> success() {
        return success(null);
    }

    protected <T> Result<T> success(T t) {
        return Result.ok(t);
    }

    public String getRoleNames() {
        String roleName = "";
        List<UserRoleDO> userRole = userRoleService.findByKv("userId", this.getUserId());
        if (userRole != null && userRole.size() > 0) {
            for (UserRoleDO roleDO : userRole) {
                RoleDO role = roleService.selectById(roleDO.getRoleId());
                roleName = roleName + role.getRoleName() + ",";
            }
        }
        return roleName;
    }

    public String getRoleNamesToken(Long userId) {
        String roleName = "";
        List<UserRoleDO> userRole = userRoleService.findByKv("userId", userId);
        if (userRole != null && userRole.size() > 0) {
            for (UserRoleDO roleDO : userRole) {
                RoleDO role = roleService.selectById(roleDO.getRoleId());
                roleName = roleName + role.getRoleName() + ",";
            }
        }
        return roleName;
    }

    public String roleCourse(HttpServletRequest req, String coursesName) {
        //查询用户角色
        String roleName = getRoleNames();
        String straa = "";
        if (!roleName.contains("超级用户角色")) {
            Long orgids;
            Object orgId = req.getSession().getAttribute("orgId");
            if (orgId != null) {
                orgids = Long.parseLong(orgId.toString());
            } else {
                orgids = this.getUser().getOrgId();
            }
            if (StringUtils.isNotBlank(coursesName)) {
                Wrapper<CoursesDO> Wrapper = new EntityWrapper<CoursesDO>().like("name", coursesName);
                List<CoursesDO> coursesDOS = coursesService.selectList(Wrapper);
                Map mapsa = new HashMap();
                mapsa.put("orgId", orgids);
                //讲师
                if (roleName.contains("讲师") && !roleName.contains("培训机构")) {
                    mapsa.put("userId", this.getUserId());
                }
                List<Long> cIds = coursesService.selCoursesIdList(mapsa);
                for (CoursesDO coursesDO : coursesDOS) {
                    if (cIds.indexOf(coursesDO.getId()) > -1) {
                        straa = straa + coursesDO.getId() + ",";
                    }
                }

            } else {
                List<CoursesDO> coursesDOS;
                if (roleName.contains("讲师") && !roleName.contains("培训机构")) {
                    coursesDOS = coursesService.findByKv("org_id", orgids, "user_id", this.getUserId());//讲师
                } else {
                    coursesDOS = coursesService.findByKv("org_id", orgids);//其他角色，比如培训机构
                }
                for (CoursesDO coursesDO : coursesDOS) {
                    straa = straa + coursesDO.getId() + ",";
                }
            }
        } else {
            //超级管理员
            if (StringUtils.isNotBlank(coursesName)) {
                Wrapper<CoursesDO> Wrapper = new EntityWrapper<CoursesDO>().like("name", coursesName);
                List<CoursesDO> coursesDOS = coursesService.selectList(Wrapper);
                for (CoursesDO coursesDO : coursesDOS) {
                    straa = straa + coursesDO.getId() + ",";
                }
            } else {
                straa = "@#$%^&*!~";
            }
        }

        return straa;
    }


    /**
     * 对考生技能考试进行分组
     *
     * @Description: 对考生技能考试进行分组，参数：调用类型（0生成试卷时，1考生分配时），试卷模板id，考试批次id
     * @Param: [type, tptemplateId, ebatchId]
     * @return: boolean
     * @Author: kl
     * @Date: 2020-06-06
     */
    public String stuGroup(int type, Long tptemplateId, Long ebatchId, Long cbatchId, Long profileId) {
        //第一步：获取本次技能考试的所有试卷
        List<ExaminationPaperDO> examinationPaperDOS;
        if (tptemplateId != null) {
            examinationPaperDOS = examinationPaperService.findByKv("tptemplate_id", tptemplateId, "ebatch_id", ebatchId);
        } else {
            examinationPaperDOS = new ArrayList<>();
        }

        //查询理论考试的考试批次
        ExaminationBatchDO examinationBatchDO = examinationBatchService.findOneByKv("type", 0, "cbatch_id", cbatchId);
        if (examinationBatchDO != null) {
            //第二步:循环利用考试批次id查询出所有考点，注意这里存的是理论考试批次id
            List<Long> orgIds = examinationPointService.selOrgIdLists(examinationBatchDO.getId());
            if (orgIds != null && orgIds.size() > 0) {
                for (Long orgID : orgIds) {
                    Map map = new HashMap();
                    map.put("cbatchId", cbatchId);
                    map.put("orgId", orgID);
                    //第三步：获取该认证批次所有已分配，有分组信息的考生;当前为技能试卷生成时，进行所有考生重新匹配试卷
                    if (type == 0) {
                        List<ExamineeGroupDO> examineeGroupDOS2 = new ArrayList<>();
                        List<ExamineeGroupDO> examineeGroupDOS1 = examineeGroupService.selAllStu(map);
                        Long epaperIdd1 = 0L;//考试试卷id
                        for (int jj = 0; jj < examineeGroupDOS1.size(); jj++) {
                            if (examinationPaperDOS != null && examinationPaperDOS.size() > 0) {
                                if ((jj + 1) % 3 == 1) {
                                    epaperIdd1 = ePaperIds(examinationPaperDOS);//随机的试卷id
                                }
                                examineeGroupDOS1.get(jj).setEpaperId(epaperIdd1);
                            }
                            examineeGroupDOS1.get(jj).setUpdaterId(this.getUserId());//修改人

                            examineeGroupDOS2.add(examineeGroupDOS1.get(jj));
                        }

                        if (examineeGroupDOS2.size() > 0) {
                            boolean b = examineeGroupService.updateBatchById(examineeGroupDOS2, examineeGroupDOS2.size());
                            if (!b) {
                                return "试卷生成成功，但与考生绑定失败;或该认证批次没有理论考试批次，请检查或删除考卷后重试！";
                            }
                        }
                    }

                    //第四步，获取考点该认证批次所有已分配，但没有分组信息的考生；对考生进行分组，如没有，直接返回
                    List<StuSignUpDO> stuSignUpDOS = examineeGroupService.selNoGroupStu(map);
                    if (stuSignUpDOS != null && stuSignUpDOS.size() > 0) {
                        //查询该考点，该考试批次已分配的考生数
                        List<ExamineeGroupDO> examineeGroupDOSaa = examineeGroupService.findByKv("org_id", orgID, "ebatch_id", ebatchId);
                        int stuAll = examineeGroupDOSaa.size() + stuSignUpDOS.size();//该考点当前总考生数
                        int maxDurationNum = maxDurationNum();//技能考试每组最大时长
                        int examinationRoomNum = examinationRoomNum();//技能考场工位数
                        long minPoor = 180L;//考试总时长，默认为三小时
                        ExaminationBatchDO examinationBatchDOss = examinationBatchService.selectById(ebatchId);
                        if (examinationBatchDOss != null) {
                            minPoor = DateUtil.getDatePoor(examinationBatchDOss.getEndTime(), examinationBatchDOss.getStartTime());//计算设置时长
                        }

                        //获取该机构的技能考场数量
                        Map mapAllNum = new HashMap();
                        mapAllNum.put("profileId", profileId);
                        mapAllNum.put("orgId", orgID);
                        int roomAllNum = examinationRoomService.selTypeCount(mapAllNum);
                        if (roomAllNum == 0) {
                            return "暂无技能考场信息，请添加后继续！";
                        }

                        long earooms;//技能考场数
                        if (((stuSignUpDOS.size() * maxDurationNum) % (minPoor * examinationRoomNum)) == 0) {
                            earooms = (stuSignUpDOS.size() * maxDurationNum) / (minPoor * examinationRoomNum);
                        } else {
                            earooms = (stuSignUpDOS.size() * maxDurationNum) / (minPoor * examinationRoomNum) + 1;
                        }

                        //第五步，根据查询出的数据，计算出考点的每教室总组数以及理想组数；根据实际情况，计算出每考场需要安排的考生组数
                        long groupNumCount;//每个教室的总组数
                        if (earooms > roomAllNum) {
                            //当需要考场比实际考场多时，每个教室总组数计算公式：（考点总考生数/实际考场数） / 技能考场工位数
                            if (((stuAll / roomAllNum) % examinationRoomNum) == 0) {
                                groupNumCount = ((stuAll / roomAllNum) / examinationRoomNum);
                            } else {
                                groupNumCount = ((stuAll / roomAllNum) / examinationRoomNum) + 1;
                            }
                        } else {
                            //当需要考场比实际考场少时，每个教室总组数计算公式：（（考试总时长/最大考试时长）*每个教室工位数） / 技能考场工位数
                            if ((minPoor % maxDurationNum) == 0) {
                                groupNumCount = minPoor / maxDurationNum;
                            } else {
                                groupNumCount = (minPoor / maxDurationNum) + 1;
                            }
                        }

                        List<ExamineeGroupDO> examineeGroupDOS = new ArrayList<>();
                        Long epaperIdd = 0L;//考试试卷id

                        //机构总考场数
                        long allRoomNum;
                        if (earooms > roomAllNum) {
                            allRoomNum = earooms;
                        } else {
                            allRoomNum = roomAllNum;
                        }

                        int startStuNum = 0;//考生开始数，考场分配后自动赋值最后分配完的考生数
                        //第六步，循环出需要添加考生的考场
                        for (int roomnn = 1; roomnn <= allRoomNum; roomnn++) {
                            Map map11 = new HashMap();
                            String roomNums11 = WithZoreUtil.frontCompWithZore(roomnn, 2);
                            map11.put("examinRoomNum", roomNums11);
                            map11.put("orgId", orgID);
                            map11.put("ebatchId", ebatchId);
                            int maxGroupNum = Integer.parseInt(examineeGroupService.selMaxGroupNum(map11));//当前考场最大组数

                            //判断最大组数是否小于总组数，如小于，则查询工位号后分配考生
                            if (maxGroupNum < groupNumCount) {
                                for (int groups = maxGroupNum; groups <= groupNumCount; groups++) {
                                    String groups11 = WithZoreUtil.frontCompWithZore(groups, 2);
                                    map11.put("groupNum", groups11);
                                    int maxStationNum = Integer.parseInt(examineeGroupService.selMaxStationNum(map11));
                                    //最大工位号小于规定工位数，进行安排,从最大工位后一位开始，不小于，不操作
                                    if (maxStationNum < examinationRoomNum) {
                                        for (int istu = maxStationNum + 1; istu <= examinationRoomNum; istu++) {
                                            //当考生数还没分配完时才分配
                                            if (startStuNum < stuSignUpDOS.size()) {
                                                ExamineeGroupDO examineeGroupDO = new ExamineeGroupDO();
                                                examineeGroupDO.setStuSignId(stuSignUpDOS.get(startStuNum).getId());//考生信息id
                                                examineeGroupDO.setOrgId(orgID);//考点id
                                                examineeGroupDO.setEbatchId(ebatchId);//考试批次id
                                                if (examinationPaperDOS != null && examinationPaperDOS.size() > 0) {
                                                    if ((istu == maxStationNum + 1) && (maxStationNum % 3 != 0) && maxStationNum != 0) {
                                                        String stationNums11 = WithZoreUtil.frontCompWithZore(maxStationNum, 2);
                                                        ExamineeGroupDO examineeGroupDO1 = examineeGroupService
                                                                .findOneByKv("org_id", orgID, "ebatch_id", ebatchId, "examin_room_num", roomNums11, "group_num", groups11, "station_num", stationNums11);
                                                        epaperIdd = examineeGroupDO1.getEpaperId();
                                                    } else if ((istu) % 3 == 1) {
                                                        epaperIdd = ePaperIds(examinationPaperDOS);//随机的试卷id
                                                    }
                                                    examineeGroupDO.setEpaperId(epaperIdd);
                                                }

                                                examineeGroupDO.setExaminRoomNum(roomNums11);//考场号
                                                examineeGroupDO.setGroupNum(groups11);//组号
                                                String stationNums = WithZoreUtil.frontCompWithZore(istu, 2);
                                                examineeGroupDO.setStationNum(stationNums);//工位号
                                                examineeGroupDO.setState(0);//默认正常
                                                examineeGroupDO.setCreaterId(this.getUserId());//创建人
                                                examineeGroupDO.setUpdaterId(this.getUserId());//修改人

                                                examineeGroupDOS.add(examineeGroupDO);
                                                startStuNum++;
                                            }
                                        }
                                    }
                                }
                            } else {
                                //如大于等于，则判断工位号是否满足，如满足直接进入下一考场，即不操作
                                String groups11 = WithZoreUtil.frontCompWithZore(maxGroupNum, 2);
                                map11.put("groupNum", maxGroupNum);
                                int maxStationNum = Integer.parseInt(examineeGroupService.selMaxStationNum(map11));
                                //工位号小于，进行安排，不小于，不操作
                                if (maxStationNum < examinationRoomNum) {
                                    for (int istu = maxStationNum + 1; istu <= examinationRoomNum; istu++) {
                                        //当考生数还没分配完时才分配
                                        if (startStuNum < stuSignUpDOS.size()) {
                                            ExamineeGroupDO examineeGroupDO = new ExamineeGroupDO();
                                            examineeGroupDO.setStuSignId(stuSignUpDOS.get(startStuNum).getId());//考生信息id
                                            examineeGroupDO.setOrgId(orgID);//考点id
                                            examineeGroupDO.setEbatchId(ebatchId);//考试批次id
                                            if (examinationPaperDOS != null && examinationPaperDOS.size() > 0) {
                                                if ((istu == maxStationNum + 1) && (maxStationNum % 3 != 0) && maxStationNum != 0) {
                                                    String stationNums11 = WithZoreUtil.frontCompWithZore(maxStationNum, 2);
                                                    ExamineeGroupDO examineeGroupDO1 = examineeGroupService
                                                            .findOneByKv("org_id", orgID, "ebatch_id", ebatchId, "examin_room_num", roomNums11, "group_num", groups11, "station_num", stationNums11);
                                                    epaperIdd = examineeGroupDO1.getEpaperId();
                                                } else if ((istu) % 3 == 1) {
                                                    epaperIdd = ePaperIds(examinationPaperDOS);//随机的试卷id
                                                }
                                                examineeGroupDO.setEpaperId(epaperIdd);
                                            }

                                            examineeGroupDO.setExaminRoomNum(roomNums11);//考场号
                                            examineeGroupDO.setGroupNum(groups11);//组号
                                            String stationNums = WithZoreUtil.frontCompWithZore(istu, 2);
                                            examineeGroupDO.setStationNum(stationNums);//工位号
                                            examineeGroupDO.setState(0);//默认正常
                                            examineeGroupDO.setCreaterId(this.getUserId());//创建人
                                            examineeGroupDO.setUpdaterId(this.getUserId());//修改人

                                            examineeGroupDOS.add(examineeGroupDO);
                                            startStuNum++;
                                        }
                                    }
                                }
                            }
                        }

                        if (examineeGroupDOS.size() > 0) {
                            boolean b = examineeGroupService.insertBatch(examineeGroupDOS, examineeGroupDOS.size());
                            if (!b) {
                                return "分配成功，技能考试分组失败，请删除考生信息重新导入或联系管理员";
                            }
                        } else {
                            return "分配失败，请联系管理员并阐述导入场景";
                        }
                    }

                }
            }
        } else {
            return "该认证批次没有理论考试批次，试卷未生成，请检查后重试！";
        }
        return "成功";
    }

    private Long ePaperIds(List<ExaminationPaperDO> examinationPaperDOS) {
        //随机获得一套试卷,并返回试卷id
        Random random = new Random();
        int n = random.nextInt(examinationPaperDOS.size());
        Long ePaperId = examinationPaperDOS.get(n).getId();
        return ePaperId;
    }

    private int maxDurationNum() {
        int maxDurationNum = 20;
        Map mapstus = new HashMap();
        mapstus.clear();
        mapstus.put("name", "技能考试每组最大时长");
        mapstus.put("type", "max_duration");
        String maxDuration = dictService.selDicBy(mapstus);
        if (org.apache.commons.lang.StringUtils.isNotBlank(maxDuration)) {
            //判断是否为数字
            if (IdCardUtil.isNumeric(maxDuration)) {
                maxDurationNum = Integer.parseInt(maxDuration);
            }
        }
        return maxDurationNum;
    }

    private int examinationRoomNum() {
        int examinationRoomNum = 6;
        Map mapstus = new HashMap();
        mapstus.put("name", "技能考场工位数");
        mapstus.put("type", "examination_room_number");
        String examinationRoomNumber = dictService.selDicBy(mapstus);
        if (org.apache.commons.lang.StringUtils.isNotBlank(examinationRoomNumber)) {
            //判断是否为数字
            if (IdCardUtil.isNumeric(examinationRoomNumber)) {
                examinationRoomNum = Integer.parseInt(examinationRoomNumber);
            }
        }
        return examinationRoomNum;
    }

    //组合证书编号
    public String comNumber(String cerNumEnd, String grade, String province, String courseName, String yearRe, String trainingMath) {
        if (grade.equals("高级师资")) {
            cerNumEnd = cerNumEnd + "10";
        } else if (grade.equals("考评员")) {
            cerNumEnd = cerNumEnd + "40";
        } else if (grade.equals("高级考评员")) {
            cerNumEnd = cerNumEnd + "30";
        } else {
            cerNumEnd = cerNumEnd + "20";
        }

        //省份
        String proCode = selProvinceCode(province);
        if (proCode.contains("错误")) {
            return "开班区域(省份)填写错误，请按照证书省份对照表填写！";
        }
        cerNumEnd = cerNumEnd + proCode + yearRe + trainingMath;

        //考核期数(从课程中截取)
        String exaNumber = courseName.substring(courseName.length() - 4, courseName.length() - 2);
        //判断是否为数字
        if (!IdCardUtil.isNumeric(exaNumber)) {
            return "课程名称" + courseName + "填写错误，期数请填写阿拉伯数字，例如：01或11;";
        }
        cerNumEnd = cerNumEnd + exaNumber;

        return cerNumEnd;
    }

    //组合证书编号
    public String comNumber1(String cerNumEnd, String grade, String province, Integer numPeriods, String yearRe, String trainingMath,String cprofileId) {
        if(cprofileId.equals(RecoveryId)){//产后恢复
            if (grade.equals("高级师资")) {
                cerNumEnd = cerNumEnd + "11";
            } else if (grade.equals("考评员")) {
                cerNumEnd = cerNumEnd + "41";
            } else if (grade.equals("高级考评员")) {
                cerNumEnd = cerNumEnd + "31";
            }
            else if (grade.equals("考务技术员")) {
                cerNumEnd = cerNumEnd + "51";
            }else if(grade.equals("考务技术员-结业证书")) {
                cerNumEnd = cerNumEnd + "61";
            }else if (grade.equals("督导员")) {
                cerNumEnd = cerNumEnd + "71";
            }else if(grade.equals("督导员-结业证书")) {
                cerNumEnd = cerNumEnd + "81";
            }
            else {
                cerNumEnd = cerNumEnd + "21";
            }
        }else{//幼儿照护
            if (grade.equals("高级师资")) {
                cerNumEnd = cerNumEnd + "10";
            } else if (grade.equals("考评员")) {
                cerNumEnd = cerNumEnd + "40";
            } else if (grade.equals("高级考评员")) {
                cerNumEnd = cerNumEnd + "30";
            }
            else if (grade.equals("考务技术员")) {
                cerNumEnd = cerNumEnd + "50";
            }else if(grade.equals("考务技术员-结业证书")) {
                cerNumEnd = cerNumEnd + "60";
            }else if (grade.equals("督导员")) {
                cerNumEnd = cerNumEnd + "70";
            }else if(grade.equals("督导员-结业证书")) {
                cerNumEnd = cerNumEnd + "80";
            }
            else {
                cerNumEnd = cerNumEnd + "20";
            }
        }


        //省份
        String proCode = selProvinceCode(province);
        if (proCode.contains("错误")) {
            return "开班区域(省份)填写错误，请按照证书省份对照表填写！";
        }
        cerNumEnd = cerNumEnd + proCode + yearRe + trainingMath + WithZoreUtil.frontCompWithZore(numPeriods, 2);

        return cerNumEnd;
    }

    public String selProvinceCode(String province) {
        if (province.equals("北京市")) {
            return "11";
        } else if (province.equals("天津市")) {
            return "12";
        } else if (province.equals("河北省")) {
            return "13";
        } else if (province.equals("山西省")) {
            return "14";
        } else if (province.equals("内蒙古")) {
            return "15";
        } else if (province.equals("辽宁省")) {
            return "21";
        } else if (province.equals("吉林省")) {
            return "22";
        } else if (province.equals("黑龙江")) {
            return "23";
        } else if (province.equals("上海市")) {
            return "31";
        } else if (province.equals("江苏省")) {
            return "32";
        } else if (province.equals("浙江省")) {
            return "33";
        } else if (province.equals("安徽省")) {
            return "34";
        } else if (province.equals("福建省")) {
            return "35";
        } else if (province.equals("江西省")) {
            return "36";
        } else if (province.equals("山东省")) {
            return "37";
        } else if (province.equals("河南省")) {
            return "41";
        } else if (province.equals("湖北省")) {
            return "42";
        } else if (province.equals("湖南省")) {
            return "43";
        } else if (province.equals("广东省")) {
            return "44";
        } else if (province.equals("广西")) {
            return "45";
        } else if (province.equals("海南省")) {
            return "46";
        } else if (province.equals("重庆市")) {
            return "50";
        } else if (province.equals("四川省")) {
            return "51";
        } else if (province.equals("贵州省")) {
            return "52";
        } else if (province.equals("云南省")) {
            return "53";
        } else if (province.equals("西藏")) {
            return "54";
        } else if (province.equals("陕西省")) {
            return "61";
        } else if (province.equals("甘肃省")) {
            return "62";
        } else if (province.equals("青海省")) {
            return "63";
        } else if (province.equals("宁夏")) {
            return "64";
        } else if (province.equals("新疆")) {
            return "65";
        } else if (province.equals("新疆兵团")) {
            return "66";
        } else if (province.equals("台湾")) {
            return "71";
        } else if (province.equals("香港")) {
            return "81";
        } else if (province.equals("澳门")) {
            return "82";
        } else if (province.equals("海外")) {
            return "91";
        } else {
            return "错误";
        }
    }

    public void delProvinEhcahe(String cType) {
        if (cType.equals("0")) {
            EhCacheUtil.put("cerNumberTra北京市", null);
            EhCacheUtil.put("cerNumberTra天津市", null);
            EhCacheUtil.put("cerNumberTra河北省", null);
            EhCacheUtil.put("cerNumberTra山西省", null);
            EhCacheUtil.put("cerNumberTra内蒙古", null);
            EhCacheUtil.put("cerNumberTra辽宁省", null);
            EhCacheUtil.put("cerNumberTra吉林省", null);
            EhCacheUtil.put("cerNumberTra黑龙江", null);
            EhCacheUtil.put("cerNumberTra上海市", null);
            EhCacheUtil.put("cerNumberTra江苏省", null);
            EhCacheUtil.put("cerNumberTra浙江省", null);
            EhCacheUtil.put("cerNumberTra安徽省", null);
            EhCacheUtil.put("cerNumberTra福建省", null);
            EhCacheUtil.put("cerNumberTra江西省", null);
            EhCacheUtil.put("cerNumberTra山东省", null);
            EhCacheUtil.put("cerNumberTra河南省", null);
            EhCacheUtil.put("cerNumberTra湖北省", null);
            EhCacheUtil.put("cerNumberTra湖南省", null);
            EhCacheUtil.put("cerNumberTra广东省", null);
            EhCacheUtil.put("cerNumberTra广西", null);
            EhCacheUtil.put("cerNumberTra海南省", null);
            EhCacheUtil.put("cerNumberTra重庆市", null);
            EhCacheUtil.put("cerNumberTra四川省", null);
            EhCacheUtil.put("cerNumberTra贵州省", null);
            EhCacheUtil.put("cerNumberTra云南省", null);
            EhCacheUtil.put("cerNumberTra西藏", null);
            EhCacheUtil.put("cerNumberTra陕西省", null);
            EhCacheUtil.put("cerNumberTra甘肃省", null);
            EhCacheUtil.put("cerNumberTra青海省", null);
            EhCacheUtil.put("cerNumberTra宁夏", null);
            EhCacheUtil.put("cerNumberTra新疆", null);
            EhCacheUtil.put("cerNumberTra新疆兵团", null);
            EhCacheUtil.put("cerNumberTra台湾", null);
            EhCacheUtil.put("cerNumberTra香港", null);
            EhCacheUtil.put("cerNumberTra澳门", null);
            EhCacheUtil.put("cerNumberTra海外", null);
        } else {
            EhCacheUtil.put("cerNumberExa北京市", null);
            EhCacheUtil.put("cerNumberExa天津市", null);
            EhCacheUtil.put("cerNumberExa河北省", null);
            EhCacheUtil.put("cerNumberExa山西省", null);
            EhCacheUtil.put("cerNumberExa内蒙古", null);
            EhCacheUtil.put("cerNumberExa辽宁省", null);
            EhCacheUtil.put("cerNumberExa吉林省", null);
            EhCacheUtil.put("cerNumberExa黑龙江", null);
            EhCacheUtil.put("cerNumberExa上海市", null);
            EhCacheUtil.put("cerNumberExa江苏省", null);
            EhCacheUtil.put("cerNumberExa浙江省", null);
            EhCacheUtil.put("cerNumberExa安徽省", null);
            EhCacheUtil.put("cerNumberExa福建省", null);
            EhCacheUtil.put("cerNumberExa江西省", null);
            EhCacheUtil.put("cerNumberExa山东省", null);
            EhCacheUtil.put("cerNumberExa河南省", null);
            EhCacheUtil.put("cerNumberExa湖北省", null);
            EhCacheUtil.put("cerNumberExa湖南省", null);
            EhCacheUtil.put("cerNumberExa广东省", null);
            EhCacheUtil.put("cerNumberExa广西", null);
            EhCacheUtil.put("cerNumberExa海南省", null);
            EhCacheUtil.put("cerNumberExa重庆市", null);
            EhCacheUtil.put("cerNumberExa四川省", null);
            EhCacheUtil.put("cerNumberExa贵州省", null);
            EhCacheUtil.put("cerNumberExa云南省", null);
            EhCacheUtil.put("cerNumberExa西藏", null);
            EhCacheUtil.put("cerNumberExa陕西省", null);
            EhCacheUtil.put("cerNumberExa甘肃省", null);
            EhCacheUtil.put("cerNumberExa青海省", null);
            EhCacheUtil.put("cerNumberExa宁夏", null);
            EhCacheUtil.put("cerNumberExa新疆", null);
            EhCacheUtil.put("cerNumberExa新疆兵团", null);
            EhCacheUtil.put("cerNumberExa台湾", null);
            EhCacheUtil.put("cerNumberExa香港", null);
            EhCacheUtil.put("cerNumberExa澳门", null);
            EhCacheUtil.put("cerNumberExa海外", null);
        }
    }

}